<script setup>
// 以24小时热榜获取数据渲染模板
import { fetchHotGoodsAPI } from "@/apis/detail";
import { ref, onMounted, computed } from "vue";
import { useRoute } from "vue-router";
// 设计props参数 适配不同的title和数据
const props = defineProps({
    hotType: {
        type: Number,  // 1代表24小时热销榜 2代表周热销榜 3代表总热销榜 可以使用type去适配title和数据列表
        default: 1
    }
})
// 适配title   1代表24小时热销榜 2代表周热销榜 3代表总热销榜
const TYPEMAP = {
    1: '24小时热榜',
    2: '周热榜',
    3: '总热销榜'
}
const title = computed(() => {
    return TYPEMAP[props.hotType]
})




// 1.封装接口
// 2.调用接口渲染模板
const hotList = ref([])
const route = useRoute()
const fetHotList = async () => {
    const res = await fetchHotGoodsAPI({
        id: route.params.id,
        type: props.hotType
        // limit: 3
    })
    console.log(';;', res);
    hotList.value = res.data.result
}
onMounted(() => {
    fetHotList()
})


</script>


<template>
  <div class="goods-hot">
    <h3>{{title}}</h3>
    <!-- 商品区块 -->
    <RouterLink to="/" class="goods-item" v-for="item in hotList" :key="item.id">
      <img :src="item.picture" alt="" />
      <p class="name ellipsis" style="margi1n: 10px">{{ item.name }}</p>
      <p class="desc ellipsis">{{ item.desc }}</p>
      <p class="price">&yen;{{ item.price }}</p>
    </RouterLink>
  </div>
</template>


<style scoped lang="scss">
.goods-hot {
  h3 {
    height: 70px;
    background: $helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }

  .goods-item {
    width: 100%;
    display: block;
    padding: 20px 30px;
    text-align: center;
    background: #fff;

    img {
      width: 160px;
      height: 160px;
    }

    p {
      padding-top: 10px;
      
    }

    .name {
      font-size: 16px;
    }
    // ::v-deep .goods-hot .goods-item[data-v-f5e250f0]{
    //   margin: 10px 0 10px;
    // }

    .desc {
      color: #999;
      height: 29px;
    }

    .price {
      color: $priceColor;
      font-size: 20px;
    }
  }
}
</style>